package m3_publishsubscribe;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import org.apache.log4j.net.SyslogAppender;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("192.168.126.130");
        cf.setUsername("admin");
        cf.setPassword("admin");
        Channel channel = cf.newConnection().createChannel();
        //定义交换机
        channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);
        //向交换机发送数据
        while (true) {
            System.out.println("输入消息：");
            String msg = new Scanner(System.in).nextLine();
            //第二个参数，对于fanout交换机无效
            channel.basicPublish("logs", "", null, msg.getBytes());
        }

    }

}
